<script>
export default {
  name: "Login",
  data() {
    return {
      user: {},
      Authorities: {
        Authority1: false,
        Authority2: false,
        Authority3: false,
        Authority4: false,
        Authority5: false,
        Authority6: false,
        Authority7: false,
        Authority8: false,
        Authority9: false,
        Authority10: false,
        Authority11: false,
        Authority12: false,
        Authority13: false,
        Authority14: false,
        Authority15: false,
        Authority16: false,
        Authority17: false,
        Authority18: false,
        Authority19: false,
        Authority20: false,
        Authority21: false,
        Authority22: false,
        Authority23: false,
        Authority24: false,
        Authority25: false,
        Authority26: false,
        Authority27: false,
        Authority28: false,
        Authority29: false,
        Authority30: false,
        Authority31: false,
        Authority32: false
      }
    }
  },
  methods: {
    login() {
      this.request.post("http://localhost:9090/user/login", this.user).then(res => {
        if(res.code !== "200") {
          this.$message.error(res.msg)
        } else {
          this.$router.push("/")
          this.$message.success("登录成功！")
          localStorage.setItem("user", JSON.stringify(res.data));
          console.log(res.data.authorityCode);
          if ((res.data.authorityCode & 1) !== 0) {
            this.Authorities.Authority1 = true;
          }
          if ((res.data.authorityCode & 2) !== 0) {
            this.Authorities.Authority2 = true;
          }
          if ((res.data.authorityCode & 4) !== 0) {
            this.Authorities.Authority3 = true;
          }
          if ((res.data.authorityCode & 8) !== 0) {
            this.Authorities.Authority4 = true;
          }
          if ((res.data.authorityCode & 16) !== 0) {
            this.Authorities.Authority5 = true;
          }
          if ((res.data.authorityCode & 32) !== 0) {
            this.Authorities.Authority6 = true;
          }
          if ((res.data.authorityCode & 64) !== 0) {
            this.Authorities.Authority7 = true;
          }
          if ((res.data.authorityCode & 128) !== 0) {
            this.Authorities.Authority8 = true;
          }
          if ((res.data.authorityCode & 256) !== 0) {
            this.Authorities.Authority9 = true;
          }
          if ((res.data.authorityCode & 512) !== 0) {
            this.Authorities.Authority10 = true;
          }
          if ((res.data.authorityCode & 1024) !== 0) {
            this.Authorities.Authority11 = true;
          }
          if ((res.data.authorityCode & 2048) !== 0) {
            this.Authorities.Authority12 = true;
          }
          if ((res.data.authorityCode & 4096) !== 0) {
            this.Authorities.Authority13 = true;
          }
          if ((res.data.authorityCode & 8192) !== 0) {
            this.Authorities.Authority14 = true;
          }
          if ((res.data.authorityCode & 16384) !== 0) {
            this.Authorities.Authority15 = true;
          }
          if ((res.data.authorityCode & 32768) !== 0) {
            this.Authorities.Authority16 = true;
          }
          if ((res.data.authorityCode & 65536) !== 0) {
            this.Authorities.Authority17 = true;
          }
          if ((res.data.authorityCode & 131072) !== 0) {
            this.Authorities.Authority18 = true;
          }
          if ((res.data.authorityCode & 262144) !== 0) {
            this.Authorities.Authority19 = true;
          }
          if ((res.data.authorityCode & 524288) !== 0) {
            this.Authorities.Authority20 = true;
          }
          if ((res.data.authorityCode & 1048576) !== 0) {
            this.Authorities.Authority21 = true;
          }
          if ((res.data.authorityCode & 2097152) !== 0) {
            this.Authorities.Authority22 = true;
          }
          if ((res.data.authorityCode & 4194304) !== 0) {
            this.Authorities.Authority23 = true;
          }
          if ((res.data.authorityCode & 8388608) !== 0) {
            this.Authorities.Authority24 = true;
          }
          if ((res.data.authorityCode & 16777216) !== 0) {
            this.Authorities.Authority25 = true;
          }
          if ((res.data.authorityCode & 33554432) !== 0) {
            this.Authorities.Authority26 = true;
          }
          if ((res.data.authorityCode & 67108864) !== 0) {
            this.Authorities.Authority27 = true;
          }
          if ((res.data.authorityCode & 134217728) !== 0) {
            this.Authorities.Authority28 = true;
          }
          if ((res.data.authorityCode & 268435456) !== 0) {
            this.Authorities.Authority29 = true;
          }
          if ((res.data.authorityCode & 536870912) !== 0) {
            this.Authorities.Authority30 = true;
          }
          if ((res.data.authorityCode & 1073741824) !== 0) {
            this.Authorities.Authority31 = true;
          }
          if ((res.data.authorityCode & -2147483648) !== 0) {
            this.Authorities.Authority32 = true;
          }
          console.log(this.Authorities);
          localStorage.setItem("authorities", JSON.stringify(this.Authorities));
        }
      })
    }
  }
}
</script>

<template>
  <div class="wrapper">
    <div style="opacity: 0.9; margin: 200px auto; background-color: #fff; width: 350px; height: 300px; padding: 20px; border-radius: 10px">
      <div style="margin: 20px 0; text-align: center; font-size: 24px"><b>登 录</b></div>
      <el-input size="medium" style="margin: 10px 0" prefix-icon="el-icon-user" v-model="user.username"></el-input>
      <el-input size="medium" style="margin: 10px 0" prefix-icon="el-icon-lock" show-password v-model="user.password"></el-input>
      <div style="margin: 10px 0; text-align: right">
        <el-button type="primary" size="small" autocomplete="off" @click="login">登录</el-button>
        <el-button type="warning" size="small" autocomplete="off" @click="$router.push('/register')">注册</el-button>
      </div>
    </div>
  </div>
</template>

<style>
  .wrapper {
    height: 100vh;
    //background-image: linear-gradient(to bottom right, #FC466B, #3F5EFB);
    background-image: url("../../public/Only_Rick.png");
    background-size: 100%, 100%;
    overflow: hidden;
  }
</style>